//
//  ST_PeculiarityTypeCell.swift
//  btvideo
//
//  Created by mac on 2020/1/15.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SwifterSwift
import SnapKit



class ST_PeculiarityTypeCell: UICollectionViewCell {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
//        contentView.backgroundColor = Color.random
        
        contentView.addSubview(cover_image_view)
        contentView.addSubview(titleLabel)
        contentView.addSubview(content_label)
        
        
        cover_image_view.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(cover_image_view.snp.width)
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(cover_image_view.snp.bottom).offset(15)
            make.centerX.equalTo(cover_image_view)
        }
        content_label.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel.snp.bottom).offset(5-2)
            make.centerX.equalTo(cover_image_view)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //    MARK: - Properties
    
    lazy var cover_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.cornerRadius = 20
        return control
    }()
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.init(hexString: "#333333")
        //        control.numberOfLines = 0
        //        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.semibold)
        return control
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.init(hexString: "#ACB4C0")
        //        control.numberOfLines = 0
        //        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        return control
    }()
    
    //    MARK:-
    var child_model = ST_PeculiarityModel(){
        didSet{
            
            cover_image_view.pin_setImage(from: child_model.image.compress_image().url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            
            titleLabel.text = child_model.name
            
            var count = 0
            
            var suffix = "个男生"
            
//            自己是男
            if let sex = ST_BTUserInfoManager.shared.current_account_info?.userinfo?.sex,sex == .male{
                suffix = "个女生"
//                同性
                if child_model.type == 1{
                    count = child_model.like_num
                }else{
                    count = child_model.own_num
                }
            }
//            自己女
            else{
//                同性
                if child_model.type == 2{
                    count = child_model.like_num
                }else{
                    count = child_model.own_num
                }
            }
            
            content_label.text = count.st_number_description() + suffix
            
        }
    }
    
}
